home *** CD-ROM | disk | FTP | other *** search
/ Software Vault: The Gold Collection / Software Vault - The Gold Collection (American Databankers) (1993).ISO / cdr49 / actlib13.zip / STRINGS.ZIP / STRCPYB.C < prev    next >
Text File  |  1993-01-14  |  699b  |  33 lines

  1. /*  Copyright (C) 1993   Marc Stern  (internet: stern@mble.philips.be)  */
  2.  
  3. #include "strings.h"
  4.  
  5.  
  6. /***
  7.  *  Function    :  strcpyb
  8.  *
  9.  *  Description :  Like strcpy but truncates trailing blanks and \n
  10.  *                 and skip leading blanks.
  11.  *
  12.  *  Parameters  :  out   char * target
  13.  *           in    char * source
  14.  *
  15.  *  Return code :  like strcpy
  16.  *
  17.  *  OS/Compiler :  All
  18.  ***/
  19.  
  20. char *strcpyb( char *target, const char *source )
  21.  
  22. { int len;
  23.  
  24.   while ( *source++ == ' ' ); source--;
  25.  
  26.   len = strlen( source );
  27.   while ( len && (source[len - 1] == ' ' || source[len - 1] == '\n') ) len--;
  28.   strncpy( target, source, len );
  29.   target[len] = '\0';
  30.  
  31.   return target;
  32. }
  33.